<!--
*@description 
*@fileName 就诊历史
*@author wxl
*@date 2025/05/11 15:29:11
!-->
<template>
   <div class="vue-box cdf">
      <div class="search-card">
         <div class="search-body">
            <el-form :inline="true" :model="formData" class="demo-form-inline">
               <el-form-item label="患者信息">
                  <el-input v-model="formData.psn_name" placeholder="请输入"  />
               </el-form-item>
               <el-form-item label="订单编号">
                  <el-input v-model="formData.OnlineInquiryNo" placeholder="请输入"  />
               </el-form-item>
               <el-form-item label="问诊药店">
                  <el-input v-model="formData.fixmedins_name" placeholder="请输入"  />
               </el-form-item>
               <el-form-item label="日期">
                  <el-date-picker
                  type="daterange"
                  v-model="formData.date"
                  format="YYYY-MM-DD"
                  value-format="YYYY-MM-DD"
                  placeholder="请选择"
                  ></el-date-picker>
               </el-form-item>
               <el-form-item label="问诊类型">
                  <el-select v-model="formData.ConsultationMethod" placeholder="请选择">
                  <el-option v-for="item in dicts.ConsultationMethod" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
               </el-form-item>
               <el-form-item label="状态">
                  <el-select v-model="formData.IsPrescription" placeholder="请选择">
                  <el-option v-for="item in dicts.IsPrescription" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
               </el-form-item>
               <el-form-item>
                  <el-button class="btn" type="primary" @click="onSearch">搜索</el-button>
                  <el-button type="default" plain icon="el-icon-Refresh" @click="sa.f5CurrView()">重置</el-button>
               </el-form-item>
            </el-form>
         </div>
      </div>
      <div class="c-card flex1 table-box">
         <div class="table-body">
            <el-table :data="tableData" row-key="fixmedins_code" stripe style="width: 100%; height: 100%" @selection-change="handleSelectionChange">
               <!-- 序号 -->
               <el-table-column
                  label="序号"
                  type="index"
                  width="60"
               ></el-table-column>
               <el-table-column v-for="(item, index) in tableCfg" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
                  <template #default="scope">
                     <span :class="{item}">
                        {{ item.formatter ? item.formatter(scope.row[item.prop]) : scope.row[item.prop] }}
                     </span>
                  </template>
               </el-table-column>
               <!-- <el-table-column fixed="right" label="操作" width="100" align="center">
                  <template #default="scope">
                     <el-button link type="danger" size="small" @click="onOffline(scope.row)" v-if="scope.row.IsOline == 1">下线</el-button>
                     <el-button link type="primary" size="small" @click="onOnline(scope.row)" v-if="scope.row.IsOline == 2">上线</el-button>
                  </template>
               </el-table-column> -->
            </el-table>
         </div>
         <!-- <div class="aicjcsb">
            <div class="margin-top">
               <el-button text type="primary" @click="multOnline">批量上线</el-button>
               <el-button text type="danger" @click="mulOffline">批量上线</el-button>
            </div>
            <table-pagin :page-no="pagin.pageNo" :page-size="pagin.pageSize" :total="pagin.total" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
         </div> -->
         <table-pagin :page-no="pagin.pageNo" :page-size="pagin.pageSize" :total="pagin.total" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
      </div>
   </div>
</template>
<script setup name="goods-list">
import { reactive,onMounted, ref } from 'vue'
// import {useRouter} from 'vue-router'
import tablePagin from '@/sa-frame/com/pagin/table-pagin.vue'
import dicts from '@/utils/dict.js'
const formData = reactive({
   ConsultationMethod: '',
   IsPrescription: ''
})
const pagin = reactive({
   pageNo: 1,
   pageSize: 10,
   total: 0,
   server_time: ''
})

const tableCfg = ref([ {
   label: '订单编号',
   prop: 'OnlineInquiryNo',
   width: '260'
}, {
   label: '患者姓名',
   prop: 'psn_name'
}, {
   label: '状态',
   prop: 'IsPrescription',
   formatter: (value) => {
      return dicts.IsPrescription.find((item) => item.value == value)?.label
    },
}, {
   label: '性别',
   prop: 'sex',
   formatter: (value) => {
      return dicts.sex.find((item) => item.value == value)?.label
    },
}, {
   label: '年龄',
   prop: 'age'
}, {
   label: '手机号码',
   prop: 'phone'
}, {
   label: '问诊类型',
   prop: 'ConsultationMethod',
   formatter: (value) => {
      return dicts.ConsultationMethod.find((item) => item.value == value)?.label
    },
}, {
   label: '问诊药店',
   prop: 'fixmedins_name',
   width: '200'
}, {
   label: '问诊时间',
   prop: 'CreateDT',
   width: '160'
}])

const tableData = ref([])
// 已选择行
const selectedRows = ref([])

// 组件加载时触发
onMounted(() => {
    f5();
})

// 搜索
function onSearch() {
   pagin.pageNo = 1
   f5()
}

// ------------------ 查找数据 ------------------
const f5 = function() {
   let params = {
      pageindex: pagin.pageNo - 1,
      pagesize: pagin.pageSize,
      ...formData,
      begintime: formData.date ? formData.date[0] : '',
      endtime: formData.date ? formData.date[1] : '',
   }
   sa.ajax('/api/webOnlineInquiry/onlineInquiryList', params, function(res) {
      tableData.value = res.data;	// 数据
      pagin.total = Number(res.totalItems);
      pagin.server_time = res.server_time
   });
};
// 表格页码切换
function handleCurrentChange(pageNo) {
   pagin.pageNo = pageNo
   console.log(' pagin.pageNo',pagin.pageNo)
   f5()
}
// 表格size修改
function handleSizeChange(pageSize) {
   pagin.pageSize = pageSize
   f5()
}
// 表格行选择
function handleSelectionChange(val) {
  console.log('handleSelectionChange',val)
  selectedRows.value = val
} 
// 批量上线
function multOnline() {
   sa.confirm('确定批量上线？', function() {

      // sa.ajax('/api/fund/storeInformationList', {
      //    ...formData
      // }, function(res) {
      //    tableData.value = res.data;	// 数据
      //    pagin.total = Number(res.totalItems);
      // }
      // )
   })
}
// 对外开放函数 
defineExpose({f5})
</script>
<style lang="scss" scoped></style>
